
      * This is an annotated version of the preceding AClass example.

      * A COBOL class consists of a number of nested source units, each
      * with the usual four divisions (IDENTIFICATION DIVISION,
      * ENVIRONMENT DIVISION, etc.). The outermost source unit in a
      * class is the class definition.
 
       IDENTIFICATION DIVISION.
       CLASS-ID. ACLASS AS "AClass".
      * The literal in the optional AS clause of a CLASS-ID paragraph
      * defines the externally visible name of the class. If omitted,
      * the isCOBOL compiler will by default use an all-uppercase
      * version of the class ID as the externally visible name. As shown
      * here, a case-sensitive PascalCase literal may be used to give
      * the class a name that resembles a Java class name. Whether you
      * assign your own literal, or accept the default all-uppercase
      * class name, the name of the COBOL source file should match your
      * choice. Otherwise the isCOBOL compiler will issue a warning.
      * In this case, the COBOL source file is "AClass.cbl".

       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
      * If your class uses any other classes, you may declare them
      * here. Precisely one period is required in a REPOSITORY, in order
      * to serve as an end marker.
           .

      *--- FACTORY DEFINITION ------------------------------------------

      * The factory definition is a nested source unit that defines what
      * a Java programmer might call the static members of the class.

       IDENTIFICATION DIVISION.
       FACTORY.

       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
      * An optional repository for any external classes that are used by
      * the factory definition. In this example, the entire ENVIRONMENT
      * DIVISION could be omitted from the factory definition.
           .

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  WS-COUNT   PIC 9(5).
       01  WS-MAX-ID  PIC 9(5).

       PROCEDURE DIVISION.

      * A method definition is a source unit that may either be nested
      * inside the PROCEDURE DIVISION of the factory definition,
      * or inside the PROCEDURE DIVISION of the object definition.
      * Examples of each case are given in this sample class.
 
       IDENTIFICATION DIVISION.
       METHOD-ID. INCREMENT-COUNT AS "incrementCount" PRIVATE.
      * The literal in the AS clause of a METHOD-ID paragraph is similar
      * to the literal in the AS clause of a CLASS-ID paragraph. It
      * defines the case-sensitive, externally visible name of the
      * method. Method names in Java use camelCase, and I have followed
      * that convention here for the externally visible names of COBOL
      * methods.
       PROCEDURE DIVISION.
           ADD 1 TO WS-COUNT
           ADD 1 TO WS-MAX-ID
      * The EXIT METHOD statement may be used if your program flow
      * requires it. Otherwise, the exit will occur when the execution
      * path "falls off the end" of the PROCEDURE DIVISION, as it does
      * here.
           .
       END METHOD.

       IDENTIFICATION DIVISION.
       METHOD-ID. DECREMENT-COUNT AS "decrementCount" PRIVATE.
       PROCEDURE DIVISION.
           SUBTRACT 1 FROM WS-COUNT
           .
       END METHOD.

       IDENTIFICATION DIVISION.
       METHOD-ID. GET-MAX-ID AS "getMaxID" PRIVATE.
       LINKAGE SECTION.
       01  LS-RESULT  PIC 9(5).
      * The RETURNING clause allows a method to return a result.
       PROCEDURE DIVISION RETURNING LS-RESULT.
           MOVE WS-MAX-ID TO LS-RESULT
           .
       END METHOD.

       IDENTIFICATION DIVISION.
       METHOD-ID. GET-COUNT AS "getCount".
       LINKAGE SECTION.
       01  LS-RESULT  PIC 9(5).
       PROCEDURE DIVISION RETURNING LS-RESULT.
           MOVE WS-COUNT TO LS-RESULT
           .
       END METHOD.

       END FACTORY.

      *--- OBJECT DEFINITION: INSTANCE MEMBERS OF THE CLASS ------------

      * The object definition is a nested source unit that defines what
      * a Java programmer might call the instance members of the class.
      * It is nested inside the class definition, at the same level as
      * the factory definition.

       IDENTIFICATION DIVISION.
       OBJECT.

       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
      * An optional repository for any external classes that are used by
      * the object definition. In this example, the entire ENVIRONMENT
      * DIVISION could be omitted from the object definition.
           .

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  WS-ID  PIC 9(5).

       PROCEDURE DIVISION.

       IDENTIFICATION DIVISION.
       METHOD-ID. NEW AS "new".
      * It appears that in isCOBOL, "new" is a special (case-sensitive)
      * method name that may be used in the object definition. My
      * understanding is that the instance method "new" is called after
      * the factory's implicit "new" method has created the object.
      * I don't think methods can be overloaded in isCOBOL 2011R3, so
      * "new" can't take any parameters. As a result, if you need to
      * initialize a new object's state beyond what's possible in a
      * parameterless constructor, then you will need to provide and
      * call another method that initializes the object. 
       PROCEDURE DIVISION.
           DISPLAY "Hello from instance method NEW."
           INVOKE AClass "incrementCount"
           SET WS-ID TO AClass:>getMaxID
           .
       END METHOD.

       IDENTIFICATION DIVISION.
       METHOD-ID. DISPOSE AS "dispose".
      * This "dispose" method is not a destructor, and is not
      * automatically called. It merely implements the "dispose" pattern
      * that is commonly used in garbage-collected languages such as
      * object-oriented COBOL. This pattern allows the user to provide
      * "cleanup" code that may be called before an object becomes
      * unreachable. An object can be explicitly made unreachable after
      * calling its "dispose" method, by setting the object to NULL.
      * The "dispose" method itself cannot set the instance to NULL.
       PROCEDURE DIVISION.
           DISPLAY "Hello from instance method DISPOSE."
           INVOKE AClass "decrementCount"
           .
       END METHOD.

       IDENTIFICATION DIVISION.
       METHOD-ID. GET-ID AS "getID".
       LINKAGE SECTION.
       01  LS-RESULT  PIC 9(5).
       PROCEDURE DIVISION RETURNING LS-RESULT.
           MOVE WS-ID TO LS-RESULT
           .
       END METHOD.

       END OBJECT.
       END CLASS.
